<?php
class libstr
{
	//判断变量是否为空
	function Ismp($str)
	{
		if (!isset($str))
		{
			return "";
		}
		if (trim($str) == "")
		{
			return "";
		}
		return $str;
	}
	//转化时间
	function formatdatetime($timegeshi,$timestr)
	{
		if($timestr=="")
		{
			return "";
		}
		// echo date("Y-m-d", strtotime(date("Y-m-d H:i:s")));
		return   date($timegeshi, strtotime($timestr));
	}
	//去除html代码
	function rehtml($str)
	{
		$pattern=array ("'<script[^>]*?>.*?</script>'si", "'<style[^>]*?>.*?</style>'si",  "'<[\/\!]*?[^<>]*?>'si",  "'([\r\n])[\s]+'",  "'&(quot|#34);'i",  "'&(amp|#38);'i",  "'&(lt|#60);'i",  "'&(gt|#62);'i",  "'&(nbsp|#160);'i",  "'&(iexcl|#161);'i",  "'&(cent|#162);'i",  "'&(pound|#163);'i",  "'&(copy|#169);'i",  "'&#(\d+);'e");
		$replace=array ("", "", "\\1", "", "&", "<", ">", " ", chr(161), chr(162), chr(163), chr(169), "chr(\\1)");
		return preg_replace ($pattern, $replace, $str);
	}
	//判断是否数字
	function isnum($str)
	{
		if(ereg("^[0-9]+$",$str))
		{
			return  true;
		}
		return false;
	}
	//获得一张图片
	function  getonepic($str="",$index=0)
	{  
		if($str=""){
			return "";
		}
		$aa=split(",",$str);
		return $aa[$index];
			}
	//获取多张图片
	function getpics($str){
		$aa=array();
		if($this->Ismp($str)==""){
			return $aa;	
		}
		$aa=split(",",$str);
		return $aa;
	}
	//获得缩略图
	function getthumbpic($str)
	{
		$arr=explode(',',$str);
		$DIRNAME=pathinfo($arr[0],PATHINFO_DIRNAME);
		$BASENAME=pathinfo($arr[0],PATHINFO_BASENAME);
		$URL=$DIRNAME.'/'.'thumb'.'/'.$BASENAME;
		return $URL;
	}
	
	//获得资源的最底层类别ID
	function  getclassid($str)
	{
		if($str=="")
		{
			return "";
		}
		$tx=split(",",$str);
		$len=count($tx);
		return $tx[$len-2];
	}
	function sethistory($str,$len=10,$ses)
	{
		if(!is_array($_SESSION[$ses]))
		{
			$k=array();
			$_SESSION[$ses]=$k;
			if($this->Ismp($_COOKIE[$ses])!="")
			{
				$hst=split(",",$_COOKIE[$ses]);
				$ik=0;
				foreach($hst as $hstx)
				{
					$_SESSION[$ses][$ik]=$hstx;
					$ik=$ik+1;
				}
			}
		}
		$ml=0;
		for($i=0;$i<count($_SESSION[$ses]);$i++)
		{
			if($_SESSION[$ses][$i]==$str)
			{
				unset($_SESSION[$ses][$i]);
				$ml=0;
			}
		}
		$_SESSION[$ses]=array_values($_SESSION[$ses]);
		if($ml==0)
		{
			if(count($_SESSION[$ses])>=$len)
			{
				array_pop($_SESSION[$ses]);
			}
			array_unshift($_SESSION[$ses],$str);
		}
		//$this->uniqueArray($_SESSION["pro_history"]);

	}
	function  getcolorw($str,$color="",$w=0)
	{
		if($color=="" && $w==0)
		{
			return $str;
		}
		if($color !="" && $w==0)
		{
			return "<font color=\"".$color."\" >".$str."</font>";
		}
		return "<font color=\"".$color."\" style=\"font-weight:bold\" >".$str."</font>";
	}
	
	
	function uniqueArray($array)

	{
		// Get unique elts as keys in assoc. array

		for ($i=0,$n=count($array, 1);$i<$n;$i++)

		$u_array[$array[$i]] = 1;

		// Copy keys only into another array

		reset($u_array, 1);

		for ($i=0,$n=count($u_array, 1);$i<$n;$i++) {

			$unduplicated_array[] = key($u_array, 1);

			next($u_array, 1);

		}

		return $unduplicated_array;

	}
	//弹出框 提示语
	function msg($str,$go="go"){
		//header("Content-Type: text/html; charset=utf-8");
		if ($go==""&&$str!=""){
			echo "<script>alert('".$str."');</script>";
			exit;
		}
		if ($go!="go"&&$str!=""){
			echo "<script>alert('".$str."');location.href='".$go."';</script>";
			exit;
		}
		if ($go=="go"&&$str!=""){
			echo "<script>alert('".$str."');history.go(-1);</script>";
			exit;
		}
		if ($str==""){
			echo "<script>location.href='".$go."';</script>";
			exit;
		}
	}
	//接收post值
	function request($str,$txstr)
	{
		$txt=$txstr;
		if($this->Ismp($_POST[$str])=="")
		{
			return $txt;
		}
		return $_POST[$str];
	}
	//接收get值
	function requestget($str,$txstr)
	{
		$txt=$txstr;
		if($this->Ismp($_GET[$str])=="")
		{
			return $txt;
		}
		return $_GET[$str];
	}

	//获得ip地址
	function getip(){
		$ip=false;
		if(!empty($_SERVER["HTTP_CLIENT_IP"])){
			$ip = $_SERVER["HTTP_CLIENT_IP"];
		}
		if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
			$ips = explode (", ", $_SERVER['HTTP_X_FORWARDED_FOR']);
			if ($ip) { array_unshift($ips, $ip); $ip = FALSE; }
			for ($i = 0; $i < count($ips); $i++) {
				if (!eregi ("^(10|172.16|192.168).", $ips[$i])) {
					$ip = $ips[$i];
					break;
				}
			}
		}
		return ($ip ? $ip : $_SERVER['REMOTE_ADDR']);
	}
	function showip($ip)
	{
		if($ip=="")
		{
			return "*.*.*.*";
		}
		$k=split("\.",$ip);
		if (count($k)!="4")
		{
			return "*.*.*.*";
		}
		return $k[0].".".$k[1].".*.*";
	}

	/**
* 获得当前网站的域名地址
*
* @param     boolean $isport 是否在返回值中添加端口信息
* @return    string
*/
	//获得当前url
	function gethost($isport = false) {
		$scheme = (isset($_SERVER['HTTPS']) && (strtolower($_SERVER['HTTPS']) != 'off')) ? 'https://' : 'http://';
		if(!empty($_SERVER['HTTP_X_FORWARDED_HOST'])) {
			$t = strpos($_SERVER['HTTP_X_FORWARDED_HOST'], ':');
			if($t > 0) {
				$host = substr($_SERVER['HTTP_X_FORWARDED_HOST'], 0, $t);
				$port = substr($_SERVER['HTTP_X_FORWARDED_HOST'], $t+1);
			} else {
				$host = $_SERVER['HTTP_X_FORWARDED_HOST'];
			}
		} else if(!empty($_SERVER['HTTP_HOST'])) {
			$t = strpos($_SERVER['HTTP_HOST'], ':');
			if($t >0) {
				$host = substr($_SERVER['HTTP_HOST'], 0, $t);
				$port = substr($_SERVER['HTTP_HOST'], $t+1);
			} else {
				$host = $_SERVER['HTTP_HOST'];
			}
		} else if(!empty($_SERVER['SERVER_NAME'])) {
			$host = $_SERVER['SERVER_NAME'];
		}
		if(empty($port)) {
			$port = $_SERVER['SERVER_PORT'];
		}
		if($isport) {
			return $scheme . $host . ':' . $port;
		} else {
			return $scheme . $host;
		}
	}
//获得系统信息
	function  getos($str="os")
	{
		// 取得浏览者操作系统及浏览器信息
		$os = $_SERVER["HTTP_USER_AGENT"];
		//分析浏览器
		if(strpos($os,"NetCaptor")) $browser="NetCaptor";
		elseif(strpos($os,"Opera")) $browser="Opera";
		elseif(strpos($os,"Firefox")) $browser="Firefox";
		elseif(strpos($os,"MSIE 8")) $browser="MSIE 8.x";
		elseif(strpos($os,"MSIE 7")) $browser="MSIE 7.x";
		elseif(strpos($os,"MSIE 6")) $browser="MSIE 6.x";
		elseif(strpos($os,"MSIE 5")) $browser="MSIE 5.x";
		elseif(strpos($os,"MSIE 4")) $browser="MSIE 4.x";
		elseif(strpos($os,"Netscape")) $browser="Netscape";
		else $browser="Other";
		// 分析操作系统
		if(strpos($os,"Windows NT 5.0")) $os="Windows 2000";
		elseif(strpos($os,"Windows NT 5.1")) $os="Windows XP";
		elseif(strpos($os,"Windows NT 5.2")) $os="Windows 2003";
		elseif(strpos($os,"Windows NT 6.0")) $os="Windows Vista";
		elseif(strpos($os,"Windows NT")) $os="Windows NT";
		elseif(strpos($os,"Windows 98")) $os="Windows 98";
		elseif(strpos($os,"unix")) $os="Unix";
		elseif(strpos($os,"linux")) $os="Linux";
		elseif(strpos($os,"SunOS")) $os="SunOS";
		elseif(strpos($os,"BSD")) $os="FreeBSD";
		elseif(strpos($os,"Mac")) $os="Mac";
		else $os="未知的操作系统";
		if(isset($_SERVER['HTTP_CLIENT_IP'])){
			$ip=$_SERVER['HTTP_CLIENT_IP'];
		} else if(isset($_SERVER['HTTP_X_FORWARDED_FOR'])){
			$ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
		} else{
			$ip=$_SERVER['REMOTE_ADDR'];
		}
		//显示浏览者信息
		//echo "IP地址：$ip";
		//echo "操作系统：$os";
		//echo "浏览器：$browser";
		if($str=="os")
		{return $os;}
		if($str=="ie")
		{return $browser;}
		if($str=="ip")
		{return $ip;}

	}

//调用编辑框
	function htmledit($htmlid,$filepath,$w,$h,$contentid,$content,$display)
	{
		if($display==0)
		{
			$display1="style=\"display:none\"";
		}
		else
		{
			$display1="";
		}
		$tx=" <IFRAME ID=\"".$htmlid."\" src=\"".$filepath."ewebeditor.htm?id=".$contentid."&style=coolblue\" frameborder=\"0\" scrolling=\"no\" width=\"".$w."\" height=\"".$h."\"></IFRAME>
		  <textarea name=\"".$contentid."\" id=\"".$contentid."\" ".$display1.">".$content."</textarea> ";
		return $tx;
	}
	//行的颜色
	function rowcolor($i,$color1,$color2)
	{
		if($i%2==0)
		{
			return $color1;
		}else{
			return $color2;
		}
	}
//去掉html的换行符等
	function formattext($Text)
	{
		$Text=htmlspecialchars($Text);
		$Text=stripslashes($Text);
		$Text=ereg_replace("\r\n","<br>",$Text);
		$Text=ereg_replace("\r","<br>",$Text);
		$Text=nl2br($Text);
		$Text=preg_replace("/\\t/is","  ",$Text);
		$Text=ereg_replace(" ","&nbsp;",$Text);
		return $Text;
	}
	function ubb($Text)
	{
		$Text=htmlspecialchars($Text);
		$Text=stripslashes($Text);
		$Text=ereg_replace("\r\n","<br>",$Text);
		$Text=ereg_replace("\r","<br>",$Text);
		$Text=nl2br($Text);
		$Text=preg_replace("/\\t/is","  ",$Text);
		$Text=ereg_replace(" ","&nbsp;",$Text);

		$Text=preg_replace("/\[h1\](.+?)\[\/h1\]/is","<h1>\\1</h1>",$Text);
		$Text=preg_replace("/\[h2\](.+?)\[\/h2\]/is","<h2>\\1</h2>",$Text);
		$Text=preg_replace("/\[h3\](.+?)\[\/h3\]/is","<h3>\\1</h3>",$Text);
		$Text=preg_replace("/\[h4\](.+?)\[\/h4\]/is","<h4>\\1</h4>",$Text);
		$Text=preg_replace("/\[h5\](.+?)\[\/h5\]/is","<h5>\\1</h5>",$Text);
		$Text=preg_replace("/\[h6\](.+?)\[\/h6\]/is","<h6>\\1</h6>",$Text);
		$Text=preg_replace("/\[center\](.+?)\[\/center\]/is","<center>\\1</center>",$Text);
		$Text=preg_replace("/\[big\](.+?)\[\/big\]/is","<big>\\1</big>",$Text);
		$Text=preg_replace("/\[small\](.+?)\[\/small\]/is","<small>\\1</small>",$Text);

		$Text=preg_replace("/\[url\](http:\/\/.+?)\[\/url\]/is","<a href=\\1>\\1</a>",$Text);
		$Text=preg_replace("/\[url\](.+?)\[\/url\]/is","<a href=\'http://\\1\'>http://\\1</a>",$Text);
		$Text=preg_replace("/\[url=(http:\/\/.+?)\](.*)\[\/url\]/is","<a href=\\1>\\2</a>",$Text);
		$Text=preg_replace("/\[url=(.+?)\](.*)\[\/url\]/is","<a href=http://\\1>\\2</a>",$Text);

		$Text=preg_replace("/\[mp\](.+?)\[\/mp\]/is","<object align=middle classid=CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95 class=OBJECT id=MediaPlayer width=450 height=350 ><param name=ShowStatusBar value=-1><param name=Filename value=\\1><embed type=application/x-oleobject codebase=http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701 flename=mp src=\\1 width=450 height=350></embed></object>",$Text);
		$Text=preg_replace("/\[flash\](.+?)\[\/flash\]/is","<OBJECT codeBase=http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=4,0,2,0 classid=clsid:D27CDB6E-AE6D-11cf-96B8-444553540000 width=500 height=400><PARAM NAME=movie VALUE=\"\\1\"><PARAM NAME=quality VALUE=high><embed src=\"\\1\" quality=high pluginspage='http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash' type='application/x-shockwave-flash' width=500 height=400>\\1</embed></OBJECT>",$Text);
		$Text=preg_replace("/\[img\](.+?)\[\/img\]/is","<img src=\\1 border=0>",$Text);
		$Text=preg_replace("/\[color=(.+?)\](.+?)\[\/color\]/is","<font color=\\1>\\2</font>",$Text);
		$Text=preg_replace("/\[size=(.+?)\](.+?)\[\/size\]/is","<font size=\\1>\\2</font>",$Text);
		$Text=preg_replace("/\[sup\](.+?)\[\/sup\]/is","<sup>\\1</sup>",$Text);
		$Text=preg_replace("/\[sub\](.+?)\[\/sub\]/is","<sub>\\1</sub>",$Text);
		$Text=preg_replace("/\[pre\](.+?)\[\/pre\]/is","<pre>\\1</pre>",$Text);
		$Text=preg_replace("/\[email\](.+?)\[\/email\]/is","<a href=mailto:\\1>\\1</a>",$Text);
		$Text=preg_replace("/\[i\](.+?)\[\/i\]/is","<i>\\1</i>",$Text);
		$Text=preg_replace("/\[b\](.+?)\[\/b\]/is","<b>\\1</b>",$Text);
		$Text=preg_replace("/\[quote\](.+?)\[\/quote\]/is","<blockquote><fontsize='1'face='CourierNew'>quote:</font><hr>\\1<hr></blockquote>",$Text);
		$Text=preg_replace("/\[code\](.+?)\[\/code\]/is","<blockquote><fontsize='1'face='TimesNewRoman'>code:</font><hr color='lightblue'><i>\\1</i><hr color='lightblue'></blockquote>",$Text);
		$Text=preg_replace("/\[sig\](.+?)\[\/sig\]/is","<div style='text-align:left;color:darkgreen;margin-left:5%'><br><br>--------------------------<br>\\1<br>--------------------------</div>",$Text);
		$Text=ereg_replace("\[hr\]","<hr>",$Text);
		return $Text;
	}
	//截取字符串
	function cutstr($string,$sublen,$hz="...")
	{
		if($sublen>=strlen($string))
		{
			return $string;
		}
		$s="";
		for($i=0;$i<$sublen;$i++)
		{
			if(ord($string{$i})>127)
			{
				$s.=$string{$i}.$string{++$i};
				continue;
			}else{
				$s.=$string{$i};
				continue;
			}
		}
		return $s.$hz;
	}
	//$cutlength 为截取的长度(即字数)
	function cut_str($sourcestr,$cutlength,$charstr="..")
	{
		$returnstr='';
		$i=0;
		$n=0;
		$str_length=strlen($sourcestr);//字符串的字节数
		while (($n<$cutlength) and ($i<=$str_length))
		{
			$temp_str=substr($sourcestr,$i,1);
			$ascnum=Ord($temp_str);//得到字符串中第$i位字符的ascii码
			if ($ascnum>=224) //如果ASCII位高与224，
			{
				$returnstr=$returnstr.substr($sourcestr,$i,3); //根据UTF-8编码规范，将3个连续的字符计为单个字符
				$i=$i+3; //实际Byte计为3
				$n++; //字串长度计1;
			}
			elseif ($ascnum>=192) //如果ASCII位高与192，
			{
				$returnstr=$returnstr.substr($sourcestr,$i,2); //根据UTF-8编码规范，将2个连续的字符计为单个字符
				$i=$i+2; //实际Byte计为2
				$n++; //字串长度计1
			}
			elseif ($ascnum>=65 && $ascnum<=90) //如果是大写字母，
			{
				$returnstr=$returnstr.substr($sourcestr,$i,1);
				$i=$i+1; //实际的Byte数仍计1个
				$n++; //但考虑整体美观，大写字母计成一个高位字符
			}
			else //其他情况下，包括小写字母和半角标点符号，
			{
				$returnstr=$returnstr.substr($sourcestr,$i,1);
				$i=$i+1; //实际的Byte数计1个
				$n=$n+0.5; //小写字母和半角标点等与半个高位字符宽...
			}
		}
		if ($str_length>$cutlength){
			$returnstr = $returnstr . $charstr;//超过长度时在尾处加上省略号
		}
		return $returnstr;

	}
	function DateDiff($d,$d1,$d2=""){   //日期比较函数
		if(is_string($d1))$d1=strtotime($d1);
		if(is_string($d2))$d2=strtotime($d2);
		if($d=="s")
		{
			return ($d2-$d1);
		}
		if($d=="d")
		{
			return ($d2-$d1)/86400;
		}
		if($d=="n")
		{
			return ($d2-$d1)/60;
		}
		if($d=="h")
		{
			return ($d2-$d1)/3600;
		}
	}
	function datetodate($d,$timestr,$day="day",$timegeshi="Y-m-d")
	{
		return date($timegeshi,strtotime("$d ".$day."",strtotime($timestr)));
	}
	function  getmatchstr($patten,$str,$arraylist)
	{
		if(preg_match_all($patten,$str,$arraylist))
		{
			return $arraylist;
		}else
		{
			return "";
		}
		//if(preg_match_all("/http:\/\/[a-zA-Z0-9][a-zA-Z0-9\/\._-]+[\.html]/",$str,$arraylist))
		//{
		//foreach ($matches[0] as $url)
		//	{
		//echo $url.'<br>';
		//}
		//}else{
		//echo '没有合适';
		//}
	}
	function getTimeDifference($time_one,$time_two)
	{
		$stamp_one=strtotime($time_one);
		$stamp_two=strtotime($time_two);
		$time_diff=abs($stamp_one-$stamp_two);
		$diff_time=getdate($time_diff);
		$diff_time["year"]-=1970;
		$diff_time["mon"]-=1;
		$diff_time["mday"]-=1;
		// ar_dump($diff_time);
		return "时间相差：".$diff_time["year"]."年".$diff_time["mon"]."月".$diff_time["mday"]."日".$diff_time["hours"]."时".$diff_time["minutes"]."分".$diff_time["seconds"];
	}
	function getweekeyday($str,$lg="cn")
	{
		$date=$str;
		date("Y-m-d", strtotime(date($date)));
		if($lg=="en")
		{
			return date("w",strtotime($date));
		}
		$d=array("日","一","二","三","四","五","六");
		echo "星期".$d[date("w",strtotime($date))];
	}
	//时间截转化为具体时间
	function gettime($str,$show="Y-m-d H:i:s"){
		$time=date($show,$str);
		return $time;
	}
	
	function showproductdengji($str)
	{
		$pic1="<img src=\"inc_0001/mvbook/image/star_red.gif\" border=\"0\">";
		$pic3="<img src=\"inc_0001/mvbook/image/star_gray.gif\" border=\"0\">";
		$pic2="<img src=\"inc_0001/mvbook/image/star_red2.gif\" border=\"0\">";
		if($str=="")
		{
			return $pic1.$pic3.$pic3.$pic3.$pic3;
		}
		if($str==0)
		{
			return $pic1.$pic3.$pic3.$pic3.$pic3;
		}
		if($str==1)
		{
			return $pic1.$pic3.$pic3.$pic3.$pic3;
		}
		if($str==2)
		{
			return $pic1.$pic1.$pic3.$pic3.$pic3;
		}
		if($str==3)
		{
			return $pic1.$pic1.$pic1.$pic3.$pic3;
		}
		if($str==4)
		{
			return $pic1.$pic1.$pic1.$pic1.$pic3;
		}
		if($str==5)
		{
			return $pic1.$pic1.$pic1.$pic1.$pic1;
		}
		if($str>1 && $str<2)
		{
			return $pic1.$pic2.$pic3.$pic3.$pic3;
		}
		if($str>2 && $str<3)
		{
			return $pic1.$pic1.$pic2.$pic3.$pic3;
		}
		if($str>3 && $str<4)
		{
			return $pic1.$pic1.$pic1.$pic2.$pic3;
		}
		if($str>4 && $str<5)
		{
			return $pic1.$pic1.$pic1.$pic1.$pic2;
		}
		if($str>5)
		{
			return $pic1.$pic1.$pic1.$pic2.$pic2;
		}
		return $pic1.$pic3.$pic3.$pic3.$pic3;

	}
	//截取中间某一段字符
	function get_substr($string,$start='0',$length='')
	{
		$start = (int)$start;
		$length = (int)$length;
		$i = 0;
		if(!$string)
		{
			return;
		}
		if($start>=0)
		{
			while($i<$start)
			{
				if(ord($string[$i])>127)
				{
					$i = $i+2;
				}
				else
				{
					$i++;
				}
			}
			$start = $i;
			if($length=='')
			{
				return substr($string,$start);
			}
			elseif($length>0)
			{
				$end = $start+$length;
				while($i<$end)
				{
					if(ord($string[$i])>127)
					{
						$i = $i+2;
					}
					else
					{
						$i++;
					}
				}
				if($end != $i-1)
				{
					$end = $i;
				}
				else
				{
					$end--;
				}
				$length = $end-$start;
				return substr($string,$start,$length);
			}
			elseif($length==0)
			{
				return;
			}
			else
			{
				$length = strlen($string)-abs($length)-$start;
				return get_substr($string,$start,$length);
			}
		}
		else
		{
			$start = strlen($string)-abs($start);
			return get_substr($string,$start,$length);
		}
	}
	//连接post传过来的id
	function getid($str)
	{
		$getid=" ";
		if(is_array($_POST[$str])){
			$getid=sprintf("%s",implode(",", $_POST[$str]));
		}
		return $getid;
	}
	
	
	//中英文都支持的字符截取
	function get_word($string, $length, $dot = '..',$charset='utf-8') { 
		if(strlen($string) <= $length) { 
		return $string; 
		} 
		$string = str_replace(array('　',' ', '&', '"', '<', '>'), array('','','&', '"', '<', '>'), $string); 
		$strcut = ''; 
		if(strtolower($charset) == 'utf-8') { 
		$n = $tn = $noc = 0; 
		while($n < strlen($string)) { 
		$t = ord($string[$n]); 
		if($t == 9 || $t == 10 || (32 <= $t && $t <= 126)) { 
		$tn = 1; $n++; $noc++; 
		} elseif(194 <= $t && $t <= 223) { 
		$tn = 2; $n += 2; $noc += 2; 
		} elseif(224 <= $t && $t < 239) { 
		$tn = 3; $n += 3; $noc += 2; 
		} elseif(240 <= $t && $t <= 247) { 
		$tn = 4; $n += 4; $noc += 2; 
		} elseif(248 <= $t && $t <= 251) { 
		$tn = 5; $n += 5; $noc += 2; 
		} elseif($t == 252 || $t == 253) { 
		$tn = 6; $n += 6; $noc += 2; 
		} else { 
		$n++; 
		} 
		if($noc >= $length) { 
		break; 
		} 
		} 
		if($noc > $length) { 
		$n -= $tn; 
		} 
		$strcut = substr($string, 0, $n); 
		} else { 
		for($i = 0; $i < $length; $i++) { 
		$strcut .= ord($string[$i]) > 127 ? $string[$i].$string[++$i] : $string[$i]; 
		} 
		} 
		return $strcut.$dot; 
	} 
	function  imgorflash($filename,$w=32,$h=32,$link="",$alt="")
	{
		$tx="";
		if($filename=="")
		{
			return "";
		}
		if (eregi(strtolower(substr($filename,-4)),".jpg,gif,.png") ==1){
			return "<a href=\"".$link."\" target=\"_blank\"><img src=\"".$filename."\" alt=\"".$alt."\" width=\"".$w."\" height=\"".$h."\" border=\"0\"></a>";
		}
		if (eregi(strtolower(substr($filename,-4)),".swf") ==1){
			$tx="";
			$tx .="<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0' width='".$w."' height='".$h."'>";
			$tx .="<param name='movie' value='".$filename."' />";
			$tx .="<param name='quality' value='high' />";
			$tx .="<embed src='".$filename."' quality='high' pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' width='".$w."' height='".$h."'></embed>";
			$tx .="</object>";
			return $tx;
		}
		return "";
	}

	function  getword($str,$dbstr)
	{
		if($_GET['web']="HTTP")
		{
			if($str=".")
			{

			}
		}
		return "";
	}
	//伪静态处理url
	function urlstr($str,$id,$ts="")
	{
		global $rewritefile;
		if($ts!="")
		{
			return $ts;
		}
		$urlstr=$str."_".$id.$rewritefile;
		if($rewritefile==".php")
		{
			$urlstr=$str.$rewritefile."?cataid=".$id;
		}
		return $urlstr;
	}
	function getcata($str)
	{
		$arr=split(",",$str);
		$ct=count($arr);
		return $arr[($ct-2)];
	}
	function urlpro($str,$id,$cataid,$ts="")
	{
		global $rewritefile;
		if($ts!="")
		{
			return $ts;
		}
		$urlstr=$str."_".$id."_".$this->getcata($cataid).$rewritefile;
		if($rewritefile==".php")
		{
			$urlstr=$str.$rewritefile."?id=".$id."&cataid=".$this->getcata($cataid);
		}
		return $urlstr;
	}
	
	function  showpic($str,$intstr=0,$mr="")
	{
		$pic= $this->getpics($str,$intstr);

		if(ereg(".",$pic)!=1)
		{
			if(strlen($mr)>0)return $mr;
			return "/uploadfile/nopic.jpg";
		}
		if(strlen(trim($pic))<1)
		{
			return $mr;
		}
		
		return $pic;
	}
	
	
	function slsql($key,$zi,$gx1="or",$gx2="or", $schar1=" ",$schar2=",")
	{
		if($key=="")
		{
			return "";
		}
		$str = "";
		$ziduan = "";
		$fg = $schar1;
		$fg1 = $schar2;
		$outstr = "";
		$guanxi = "";
		$guanxi1 = "";
		$k1 = "";
		$k2 = "";
		$xxx="";
		$x="";
		$f=0;
		$i=0;
		$f1=0;
		$i1=0;
		$str = $key;
		$ziduan = $zi;
		$guanxi = " ".$gx1." ";
		$guanxi1 = ") ".$gx2." (";
		if (trim($str) != "")
		{
			$k1 = "(";
			$k2 = ")";
		}
		if ($ziduan == "")
		{
			return "";
		}
		if ($str == "")
		{
			$guanxi1 = "";
		}
		$x = split($fg1,$ziduan);
		$f1 = (count($x));
		for ($i1 = 0; $i1 < $f1; $i1++)
		{
			if ($i1 == $f1 - 1)
			{
				$guanxi1 = "";
			}
			$xxx = split($fg,$str);
			$f = (count($xxx));
			for ($i = 0; $i<$f; $i++)
			{
				if (($i1) > 0)
				{
					$guanxi = " ".$gx1." ";
				}
				if (($i) == ((count($xxx) - 1)))
				{
					$guanxi = "";
				}
				if (trim($xxx[$i]) != "")
				{
					$outstr = $outstr.trim($x[$i1])." like " . "'%" .trim($xxx[$i]) . "%'" . $guanxi;
				}
			}
			$outstr = $outstr . $guanxi1;
		}
		$outstr = $k1 . $outstr . $k2;
		return "(".(trim($outstr)).")";
		//$outstr = "";
	}
	function  shengri($str)
	{
		if(ereg("1905-12-21",$str)==1)
		{
			return  "";
		}
		return $this->formatdatetime("Y-m-d",$str);
	}

	function delhtml($str){   //清除HTML标签
		$st=-1; //开始
		$et=-1; //结束
		$stmp=array();
		$stmp[]="&nbsp;";
		$len=strlen($str);
		for($i=0;$i<$len;$i++){
			$ss=substr($str,$i,1);
			if(ord($ss)==60){ //ord("<")==60
				$st=$i;
			}
			if(ord($ss)==62){ //ord(">")==62
				$et=$i;
				if($st!=-1){
					$stmp[]=substr($str,$st,$et-$st+1);
				}
			}
		}
		$str=str_replace($stmp,"",$str);
		return $str;
	}
	//转换大小kb转mb
function tranbig($daxiao){

if($daxiao>=1024){
$daxiao=number_format($daxiao/1024,2)."MB";
}
else{
$daxiao=number_format($daxiao,2)."KB";

}
return $daxiao;
}
}


//echo substr_count(strtolower("您叫谢广泉，我叫谢广泉，谢谢okOK"),"ok");
?>